#!/bin/bash
###
 # @Author: dvlproad
 # @Date: 2023-04-29 15:23:47
 # @LastEditors: dvlproad
 # @LastEditTime: 2023-05-27 21:24:48
 # @Description: 
### 
:<<!
branchLogType:
full
short
none
!

CurrentDIR_Script_Absolute="$( cd "$( dirname "$0" )" && pwd )"
#echo "CurrentDIR_Script_Absolute=${CurrentDIR_Script_Absolute}"
#bulidScriptCommon_dir_Absolute=${CurrentDIR_Script_Absolute%/*}
bulidScriptCommon_dir_Absolute=${CurrentDIR_Script_Absolute}

qscript_path_get_filepath="${bulidScriptCommon_dir_Absolute}/qscript_path_get.sh"
qbase_update_json_file_singleString_script_path="$(sh ${qscript_path_get_filepath} qbase update_json_file_singleString)"

FILE_PATH="../bulidScript/app_info.json"

source ${bulidScriptCommon_dir_Absolute}/a_function.sh ${bulidScriptCommon_dir_Absolute}
FILE_PATH="FILE_PATH/a/b"
ipa_file_path="ipa_file_path/a/b"
upload_continueScriptFile="upload_continueScriptFile/a/df"
out_output_dir="out_output_dir/ab/cd"

copy_from_dir_path=$(dirname "$ipa_file_path")
addExtraPaths=""
addExtraPaths+=("${FILE_PATH}")
addExtraPaths+=("${upload_continueScriptFile}")
echo "=====所有待添加的路径 addExtraPaths =${addExtraPaths[*]}"
copyAllFileToFrom_andBackUpTo -copyDirFrom "${copy_from_dir_path}" -addAppInfoF "${FILE_PATH}" -addExtraPaths "${addExtraPaths[*]}" -copyDirTo "${out_output_dir}"

echo "---------------------------------------------------"

#[shell 判断字符串是否存在数组中](https://blog.csdn.net/zzhongcy/article/details/122582351)
##数组
array=(
address
base
cart
company
store
)
 
# $1 如果存在，输出 $1 exists，$1 如果不存在，输出 $1 not exists
#if [ "$1" != "" ];then
#    if [[ "${array[@]}"  =~ "${1}" ]]; then
#        echo "$1 exists"
#    elif [[ ! "${array[@]}"  =~ "${1}" ]]; then
#        echo "$1 not exists"
#    fi
#else
#    echo "请传入一个参数"
#fi
# 使用 =~会有问题：问题：包含关系也能通过(add匹配address通过)

noBranchNames=("HEAD" "->")
mergeBranchName="->" 
if echo "${noBranchNames[@]}" | grep -wq "${mergeBranchName}" &>/dev/null; then # mergeBranchName="->" 识别错误
    echo "${mergeBranchName}:pass 不是分支名，过滤掉"
else
    echo "${mergeBranchName}:ok"
fi
exit

if echo "${array[@]}" | grep -wq "${1}" &>/dev/null; then
    echo "Found"
else
    echo "NoFound"
fi

isContainInArray "${array}" ${1}
echo "=========$?"




CUR_DIR=$PWD    #$PWD代表获取当前路径，当cd后，$PWD也会跟着更新到新的cd路径。这个和在终端操作是一样的道理的
WORKSPACE="${CUR_DIR%/*}" # 使用此方法可以避免路径上有..
echo "CUR_DIR=$CUR_DIR"
echo "WORKSPACE=$WORKSPACE"

# 获取featureBrances文件夹下的所有分支json组成数组，添加到${FILE_PATH}的feature_brances中
ignoreAddJsonFileNames=("dev_demo.json")
read_feature_brances_JsonStrings_and_addToAppInfoJsonFile -appBranchsDir "../bulidScript/featureBrances" -appInfoF ${FILE_PATH} -ignoreAddJsonFileNames "${ignoreAddJsonFileNames}"
if [ $? != 0 ]; then
    exit_script
fi
    
ipa_file_path="$PWD/check_can_package/get_all_merger_branch_names.sh"
out_output_dir="${WORKSPACE%/*}/all_ipa_output" # 取WORKSPACE这个文件夹所在的上层文件目录，加上all_ipa_output

appJsonFile_dir=$(dirname "$FILE_PATH")
upload_continueScriptFile="${appJsonFile_dir}/upload_continue.sh"
copyAllFileToFrom_andBackUpTo -copyDirFrom "${copy_from_dir_path}" -addAppInfoF "${FILE_PATH}" -addExtraPaths "${addExtraPaths[*]}" -copyDirTo "${out_output_dir}"

echo "\n\n\n\n"

# 方法1：
#sh sed_text.sh -appInfoF ${FILE_PATH} -r "pack doing" -t "pack finished"
# 方法2：
sh ${qbase_update_json_file_singleString_script_path} -jsonF "${FILE_PATH}" -k "packing_state" -v "pack finished"

exit_script
